package game.state;

import game.engine.*;

import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class Play extends BasicGameState {
	private static GameContainer myContainer;

	// to allow us for consistent tick intervals
	private int timeSinceLastTick = 0;
	private int state;
	private Hero myCharacter;
	private World myWorld;

	public Play(int state) {
		this.state = state;
	}

	@Override
	public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
		myWorld = new World();
		myWorld.init();
		myCharacter = new Hero("FagFace", "data/test");
		myCharacter.init();
		myCharacter.setX(1);
		myCharacter.setY(1);
		myWorld.addEntity(myCharacter);
	}

	@Override
	public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
		g.drawString("BOOMERGUY", 16, 16);
		myWorld.render();
	}

	@Override
	public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
		timeSinceLastTick += delta;
		if (timeSinceLastTick >= GameConstants.TICK_SPEED) {
			timeSinceLastTick -= GameConstants.TICK_SPEED;
			myContainer = gc;

			// Update all entities on the map
			myWorld.updateAllEntities(GameConstants.TICK_SPEED);
		}

	}

	public static Input getInput() {
		return myContainer.getInput();
	}

	@Override
	public int getID() {
		return state;
	}

}
